Conditions | 1 |
Paths | > 20000 |
Total Lines | 122 |
Code Lines | 86 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | // Buttons |
||
11 | }(function($, PNotify){ |
||
12 | PNotify.prototype.options.buttons = { |
||
13 | // Provide a button for the user to manually close the notice. |
||
14 | closer: true, |
||
15 | // Only show the closer button on hover. |
||
16 | closer_hover: true, |
||
17 | // Provide a button for the user to manually stick the notice. |
||
18 | sticker: true, |
||
19 | // Only show the sticker button on hover. |
||
20 | sticker_hover: true, |
||
21 | // The various displayed text, helps facilitating internationalization. |
||
22 | labels: { |
||
23 | close: "Close", |
||
24 | stick: "Stick" |
||
25 | } |
||
26 | }; |
||
27 | PNotify.prototype.modules.buttons = { |
||
28 | // This lets us update the options available in the closures. |
||
29 | myOptions: null, |
||
30 | |||
31 | closer: null, |
||
32 | sticker: null, |
||
33 | |||
34 | init: function(notice, options){ |
||
35 | var that = this; |
||
36 | this.myOptions = options; |
||
37 | notice.elem.on({ |
||
38 | "mouseenter": function(e){ |
||
|
|||
39 | // Show the buttons. |
||
40 | if (that.myOptions.sticker && !(notice.options.nonblock && notice.options.nonblock.nonblock)) that.sticker.trigger("pnotify_icon").css("visibility", "visible"); |
||
41 | if (that.myOptions.closer && !(notice.options.nonblock && notice.options.nonblock.nonblock)) that.closer.css("visibility", "visible"); |
||
42 | }, |
||
43 | "mouseleave": function(e){ |
||
44 | // Hide the buttons. |
||
45 | if (that.myOptions.sticker_hover) |
||
46 | that.sticker.css("visibility", "hidden"); |
||
47 | if (that.myOptions.closer_hover) |
||
48 | that.closer.css("visibility", "hidden"); |
||
49 | } |
||
50 | }); |
||
51 | |||
52 | // Provide a button to stick the notice. |
||
53 | this.sticker = $("<div />", { |
||
54 | "class": "ui-pnotify-sticker", |
||
55 | "css": {"cursor": "pointer", "visibility": options.sticker_hover ? "hidden" : "visible"}, |
||
56 | "click": function(){ |
||
57 | notice.options.hide = !notice.options.hide; |
||
58 | if (notice.options.hide) |
||
59 | notice.queueRemove(); |
||
60 | else |
||
61 | notice.cancelRemove(); |
||
62 | $(this).trigger("pnotify_icon"); |
||
63 | } |
||
64 | }) |
||
65 | .bind("pnotify_icon", function(){ |
||
66 | $(this).children().removeClass(notice.styles.pin_up+" "+notice.styles.pin_down).addClass(notice.options.hide ? notice.styles.pin_up : notice.styles.pin_down); |
||
67 | }) |
||
68 | .append($("<span />", {"class": notice.styles.pin_up, "title": options.labels.stick})) |
||
69 | .prependTo(notice.container); |
||
70 | if (!options.sticker || (notice.options.nonblock && notice.options.nonblock.nonblock)) |
||
71 | this.sticker.css("display", "none"); |
||
72 | |||
73 | // Provide a button to close the notice. |
||
74 | this.closer = $("<div />", { |
||
75 | "class": "ui-pnotify-closer", |
||
76 | "css": {"cursor": "pointer", "visibility": options.closer_hover ? "hidden" : "visible"}, |
||
77 | "click": function(){ |
||
78 | notice.remove(false); |
||
79 | that.sticker.css("visibility", "hidden"); |
||
80 | that.closer.css("visibility", "hidden"); |
||
81 | } |
||
82 | }) |
||
83 | .append($("<span />", {"class": notice.styles.closer, "title": options.labels.close})) |
||
84 | .prependTo(notice.container); |
||
85 | if (!options.closer || (notice.options.nonblock && notice.options.nonblock.nonblock)) |
||
86 | this.closer.css("display", "none"); |
||
87 | }, |
||
88 | update: function(notice, options){ |
||
89 | this.myOptions = options; |
||
90 | // Update the sticker and closer buttons. |
||
91 | if (!options.closer || (notice.options.nonblock && notice.options.nonblock.nonblock)) |
||
92 | this.closer.css("display", "none"); |
||
93 | else if (options.closer) |
||
94 | this.closer.css("display", "block"); |
||
95 | if (!options.sticker || (notice.options.nonblock && notice.options.nonblock.nonblock)) |
||
96 | this.sticker.css("display", "none"); |
||
97 | else if (options.sticker) |
||
98 | this.sticker.css("display", "block"); |
||
99 | // Update the sticker icon. |
||
100 | this.sticker.trigger("pnotify_icon"); |
||
101 | // Update the hover status of the buttons. |
||
102 | if (options.sticker_hover) |
||
103 | this.sticker.css("visibility", "hidden"); |
||
104 | else if (!(notice.options.nonblock && notice.options.nonblock.nonblock)) |
||
105 | this.sticker.css("visibility", "visible"); |
||
106 | if (options.closer_hover) |
||
107 | this.closer.css("visibility", "hidden"); |
||
108 | else if (!(notice.options.nonblock && notice.options.nonblock.nonblock)) |
||
109 | this.closer.css("visibility", "visible"); |
||
110 | } |
||
111 | }; |
||
112 | $.extend(PNotify.styling.jqueryui, { |
||
113 | closer: "ui-icon ui-icon-close", |
||
114 | pin_up: "ui-icon ui-icon-pin-w", |
||
115 | pin_down: "ui-icon ui-icon-pin-s" |
||
116 | }); |
||
117 | $.extend(PNotify.styling.bootstrap2, { |
||
118 | closer: "icon-remove", |
||
119 | pin_up: "icon-pause", |
||
120 | pin_down: "icon-play" |
||
121 | }); |
||
122 | $.extend(PNotify.styling.bootstrap3, { |
||
123 | closer: "glyphicon glyphicon-remove", |
||
124 | pin_up: "glyphicon glyphicon-pause", |
||
125 | pin_down: "glyphicon glyphicon-play" |
||
126 | }); |
||
127 | $.extend(PNotify.styling.fontawesome, { |
||
128 | closer: "fa fa-times", |
||
129 | pin_up: "fa fa-pause", |
||
130 | pin_down: "fa fa-play" |
||
131 | }); |
||
132 | })); |
||
133 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.